﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace WinFormsExer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string path1 = "..\\..\\..\\text1.txt";
            string path2 = "..\\..\\..\\text2.txt"; ;
            string path3 = "..\\..\\..\\text3.txt"; ;
            string path = "Data\\text.txt";
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    try
                    {
                        FileStream fin = new FileStream(path1, FileMode.Open, FileAccess.Read);
                        FileStream fout = new FileStream(path, FileMode.Create, FileAccess.Write);
                        using (StreamReader reader = new StreamReader(fin, Encoding.Default))
                        {
                            using (StreamWriter writer = new StreamWriter(fout, Encoding.Default))
                            {
                                string s = null;
                                while ((s = reader.ReadLine()) != null)
                                {
                                    writer.WriteLine(s);
                                }
                            }
                        }
                    }
                    catch(FileNotFoundException)
                    {
                        Console.WriteLine("File not found");
                    }
                    catch(IOException e2)
                    {
                        Console.WriteLine(e2);
                    }
                    break;
                case 1:
                    try
                    {
                        FileStream fin = new FileStream(path2, FileMode.Open, FileAccess.Read);
                        FileStream fout = new FileStream(path, FileMode.Create, FileAccess.Write);
                        using (StreamReader reader = new StreamReader(fin, Encoding.Default))
                        {
                            using (StreamWriter writer = new StreamWriter(fout, Encoding.Default))
                            {
                                string s = null;
                                while ((s = reader.ReadLine()) != null)
                                {
                                    writer.WriteLine(s);
                                }
                            }
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        Console.WriteLine("File not found");
                    }
                    catch (IOException e2)
                    {
                        Console.WriteLine(e2);
                    }
                    break;
                case 2:
                    try
                    {
                        FileStream fin = new FileStream(path3, FileMode.Open, FileAccess.Read);
                        FileStream fout = new FileStream(path, FileMode.Create, FileAccess.Write);
                        using (StreamReader reader = new StreamReader(fin, Encoding.Default))
                        {
                            using (StreamWriter writer = new StreamWriter(fout, Encoding.Default))
                            {
                                string s = null;
                                while ((s = reader.ReadLine()) != null)
                                {
                                    writer.WriteLine(s);
                                }
                            }
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        Console.WriteLine("File not found");
                    }
                    catch (IOException e2)
                    {
                        Console.WriteLine(e2);
                    }
                    break;

            }
            switch (comboBox2.SelectedIndex)
            {
                case 0:
                    try
                    {
                        FileStream fin = new FileStream(path1, FileMode.Open, FileAccess.Read);
                        FileStream fout = new FileStream(path, FileMode.Append, FileAccess.Write);
                        using (StreamReader reader = new StreamReader(fin, Encoding.Default))
                        {
                            using (StreamWriter writer = new StreamWriter(fout, Encoding.Default))
                            {
                                string s = null;
                                while ((s = reader.ReadLine()) != null)
                                {
                                    writer.WriteLine(s);
                                }
                            }
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        Console.WriteLine("File not found");
                    }
                    catch (IOException e2)
                    {
                        Console.WriteLine(e2);
                    }
                    break;
                case 1:
                    try
                    {
                        FileStream fin = new FileStream(path2, FileMode.Open, FileAccess.Read);
                        FileStream fout = new FileStream(path, FileMode.Append, FileAccess.Write);
                        using (StreamReader reader = new StreamReader(fin, Encoding.Default))
                        {
                            using (StreamWriter writer = new StreamWriter(fout, Encoding.Default))
                            {
                                string s = null;
                                while ((s = reader.ReadLine()) != null)
                                {
                                    writer.WriteLine(s);
                                }
                            }
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        Console.WriteLine("File not found");
                    }
                    catch (IOException e2)
                    {
                        Console.WriteLine(e2);
                    }
                    break;
                case 2:
                    try
                    {
                        FileStream fin = new FileStream(path3, FileMode.Open, FileAccess.Read);
                        FileStream fout = new FileStream(path, FileMode.Append, FileAccess.Write);
                        using (StreamReader reader = new StreamReader(fin, Encoding.Default))
                        {
                            using (StreamWriter writer = new StreamWriter(fout, Encoding.Default))
                            {
                                string s = null;
                                while ((s = reader.ReadLine()) != null)
                                {
                                    writer.WriteLine(s);
                                }
                            }
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        Console.WriteLine("File not found");
                    }
                    catch (IOException e2)
                    {
                        Console.WriteLine(e2);
                    }
                    break;

            }


        }

        private void button3_Click(object sender, EventArgs e)
        {
            label6.Text = "";
            string path = "Data\\text.txt";
            FileStream fin = new FileStream(path, FileMode.Open, FileAccess.Read);
            using (StreamReader reader = new StreamReader(fin, Encoding.Default))
            {
                
                    string s = null;
                    while ((s = reader.ReadLine()) != null)
                    {
                    label6.Text += s;
                    label6.Text += "\n";
                }
                
            }
        }
    }
}
